package com.seveneight.baijiesteward.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.seveneight.baijiesteward.R;
import com.seveneight.baijiesteward.bean.PlanDetailListInfoBean;
import com.seveneight.baijiesteward.bean.RankListBean;
import com.seveneight.baijiesteward.utils.DateUtil;

import java.util.List;

/**
 * 计划列表详情adapter
 * Created by user1 on 2018/5/31.
 */

public class PlanListInfoAdapter extends BaseAdapter {
    LayoutInflater mInflater;
    List<PlanDetailListInfoBean> listData;
    Activity activity;
    public PlanListInfoAdapter(Activity activity, List<PlanDetailListInfoBean> listData){
        mInflater = LayoutInflater.from(activity);
        this.activity=activity;
        this.listData=listData;
    }

    @Override
    public int getCount() {
        return null==listData?0:listData.size();
    }
    public void refresh(List<PlanDetailListInfoBean> listData){
        this.listData=listData;
        this.notifyDataSetChanged();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return null==listData?0:listData.size();
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_plan_pay_list_info_layout, null); //加载布局
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {   //else里面说明，convertView已经被复用了，说明convertView中已经设置过tag了，即holder
            holder = (ViewHolder) convertView.getTag();
         }
        PlanDetailListInfoBean bean=listData.get(i);
        if (null != bean.getExecuteTime()){
            holder.pay_info_date.setText("日期"+bean.getExecuteTime().replace("T"," 时间 "));
        }
        holder.repay_money.setText(bean.getAomunt()+"元");
        if (bean.getPlanType().equals("0")){
            holder.pay_or_recharge.setText("消费账单");
            holder.repay_photo.setImageResource(R.mipmap.recharge_image);
        }else {
            holder.pay_or_recharge.setText("还款账单");
            holder.repay_photo.setImageResource(R.mipmap.repay_image);
        }
        holder.error_message.setVisibility(View.GONE);
//        holder.plan_no.setText("订单号 :   "+bean.getPlanNo());
//         holder.brokerage.setText("还款手续费 ￥"+(bean.getRepayCount()*bean.getBrokerage())+"");
//         holder.item_plan_date.setText("提交日期"+DateUtil.formatDate(bean.getCreatorTime()));
//         holder.service_charge.setText("消费手续费 ￥"+(bean.getServiceCharge()-(bean.getRepayCount()*bean.getBrokerage()))+"");
//         holder.repay_amount1.setText("消费金额 ￥"+bean.getRechargeAmount());
//         holder.repay_amount.setText("还款金额 ￥"+bean.getRechargeAmount());
         if (bean.getExecuteResult()==4){
             holder.pay_type.setText("执行成功");
             holder.pay_type.setTextColor(Color.parseColor("#58de74"));
         }else if(bean.getExecuteResult()==3){
             holder.pay_type.setText("执行中");
             holder.pay_type.setTextColor(Color.parseColor("#53affe"));
         }else if(bean.getExecuteResult()==2){
             holder.pay_type.setText("执行失败");
             holder.pay_type.setTextColor(Color.parseColor("#fd4519"));
             holder.error_message.setVisibility(View.VISIBLE);
             holder.error_message.setText("失败详情:"+bean.getMessage());
         }else if(bean.getExecuteResult()==1){
             holder.pay_type.setText("等待执行");
             holder.pay_type.setTextColor(Color.parseColor("#ffa400"));
         }
//         holder.item_pay_time.setText(bean.getExecuteTime());
//         if (null != bean.getList()){
//
//         }

        return convertView;
    }

    public class ViewHolder{
        TextView pay_info_date;
        TextView repay_money;
        TextView pay_or_recharge;
        TextView pay_type;
        TextView error_message;
        ImageView repay_photo;

        ViewHolder(View view){
            pay_info_date=view.findViewById(R.id.pay_info_date);
            repay_money=view.findViewById(R.id.repay_money);
            pay_or_recharge=view.findViewById(R.id.pay_or_recharge);
            repay_photo=view.findViewById(R.id.repay_photo);
            pay_type=view.findViewById(R.id.pay_type);
            error_message=view.findViewById(R.id.error_message);
        }
    };
}
